/* GUI CONVERTED from resubis.p (converter v1.76) Sun Aug 25 20:59:57 2002 */
/* resubis.p - REPETITIVE SUBCONTRACT SHIPPER CONFIRM                        */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/* $Revision: 1.10.1.25 $                                                              */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*               */
/* REVISION: 7.3      LAST MODIFIED: 11/03/94   BY: WUG *GN98*               */
/* REVISION: 7.3      LAST MODIFIED: 02/11/95   BY: ljm *G0DZ*               */
/* REVISION: 7.3      LAST MODIFIED: 02/28/95   BY: WUG *G0G2*               */
/* REVISION: 8.5      LAST MODIFIED: 05/13/95   BY: pma *J04T*               */
/* REVISION: 8.5      LAST MODIFIED: 05/01/96   BY: jym *G1MN*               */
/* REVISION: 8.5      LAST MODIFIED: 05/21/96   BY: *H0L4* Julie Milligan    */
/* REVISION: 8.6      LAST MODIFIED: 06/11/96   BY: ejh *K001*               */
/* REVISION: 8.5      LAST MODIFIED: 06/18/96   BY: *J0V0* Tamra Farnsworth  */
/* REVISION: 8.6      LAST MODIFIED: 10/18/96   BY: *K003* Vinay Nayak-Sujir */
/* REVISION: 8.6      LAST MODIFIED: 12/26/96   BY: *H0Q8* Julie Milligan    */
/* REVISION: 8.6      LAST MODIFIED: 03/15/97   BY: *K04X* Steve Goeke       */
/* REVISION: 8.6      LAST MODIFIED: 04/09/97   BY: *K08N* Steve Goeke       */
/* REVISION: 8.6      LAST MODIFIED: 04/15/96   BY: *K08N* Vinay Nayak-Sujir */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan        */
/* REVISION: 8.6E     LAST MODIFIED: 08/17/98   BY: *H1J5* Dana Tunstall     */
/* REVISION: 8.6E     LAST MODIFIED: 08/25/98   BY: *L07J* Steve Nugent      */
/* REVISION: 9.0      LAST MODIFIED: 03/29/99   BY: *J3BM* Reetu Kapoor      */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Jeff Wootton      */
/* REVISION: 9.1      LAST MODIFIED: 10/25/99   BY: *N002* Bill Gates        */
/* REVISION: 9.1      LAST MODIFIED: 11/17/99   BY: *N04H* Vivek Gogte       */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1      LAST MODIFIED: 06/28/00   BY: *N0DM* Rajinder Kamra    */
/* REVISION: 9.1      LAST MODIFIED: 07/13/00   BY: *N0DR* Bill Gates        */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* myb               */
/* REVISION: 9.1      LAST MODIFIED: 09/14/00   BY: *L13V* Vandna Rohira     */
/* REVISION: 9.1      LAST MODIFIED: 12/18/00   BY: *L16R* Reetu Kapoor      */
/* Old ECO marker removed, but no ECO header exists *F0PN*                   */
/* REVISION: 9.1      LAST MODIFIED: 09/28/00   BY: *N0WD* Mudit Mehta       */
/* REVISION: 9.1      LAST MODIFIED: 02/22/01   BY: *N0X2* Sathish Kumar     */
/* Revision: 1.10.1.19    BY: Niranjan R.    DATE: 07/13/01  ECO: *P00L*     */
/* Revision: 1.10.1.21    BY: Sathish Kumar  DATE: 12/24/01  ECO: *N12R*     */
/* Revision: 1.10.1.22    BY: Ellen Borden   DATE: 06/07/01  ECO: *P00G*     */
/* Revision: 1.10.1.23    BY: Samir Bavkar   DATE: 04/05/02  ECO: *P000*     */
/* Revision: 1.10.1.24    BY: Jeff Wootton   DATE: 05/14/02  ECO: *P03G*     */
/* $Revision: 1.10.1.25 $           BY: Vivek Gogte    DATE: 08/06/02  ECO: *N1QQ*     */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/*V8:ConvertMode=Maintenance                                                 */

{mfdtitle.i "2+ "}
{cxcustom.i "RESUBIS.P"}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE resubis_p_1 "Ship-From Site"
/* MaxLen: Comment: */

&SCOPED-DEFINE resubis_p_2 "Shipper ID"
/* MaxLen: Comment: */

&SCOPED-DEFINE resubis_p_3 "Unit Cost"
/* MaxLen: Comment: */

&SCOPED-DEFINE resubis_p_4 "Effective"
/* MaxLen: Comment: */

&SCOPED-DEFINE resubis_p_5 "Conversion"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

{gldydef.i new}
{gldynrm.i new}

{gpglefv.i}
define shared variable global_recid as recid.
define new shared variable transtype as character.
define new shared variable ref like glt_ref.
define new shared variable issrct as character format "x(3)".
define new shared variable conv like um_conv
   label {&resubis_p_5} no-undo.
define new shared variable eff_date like glt_effdate label {&resubis_p_4}.
define new shared variable trlot like tr_lot.
define new shared variable unit_cost like tr_price label {&resubis_p_3}.
define new shared variable ordernbr like tr_nbr.
define new shared variable orderline like tr_line.
define new shared variable so_job like tr_so_job.
define new shared variable addr like tr_addr.
define new shared variable rmks like tr_rmks.
define new shared variable dr_acct like trgl_dr_acct.
define new shared variable dr_sub like trgl_dr_sub.
define new shared variable dr_cc like trgl_dr_cc.
define new shared variable cr_acct like trgl_cr_acct.
define new shared variable cr_sub like trgl_cr_sub.
define new shared variable cr_cc like trgl_cr_cc.
define new shared variable project like wo_proj.
define new shared variable lotserial_qty like sr_qty no-undo.
define new shared variable part like tr_part.
define new shared variable um like pt_um no-undo.
define new shared variable site like sr_site no-undo.
{&RESUBIS-P-TAG1}

define buffer prev_wr_route for wr_route.
define buffer prev_milestone_wr_route for wr_route.

define variable abs_carr_ref as character.
define variable abs_fob like so_fob.
define variable abs_recid as recid.
define variable abs_shipvia like so_shipvia.
define variable abs_trans_mode as character.
define variable abs_veh_ref as character.
define variable assay like tr_assay.
define variable disp_abs_id like abs_mstr.abs_id.
define variable expire as date.
define variable glcost as decimal.
define variable grade as character.
define variable operation_wip_mtl as logical.
define variable ophist_recid as recid.
define variable ship_dt like so_ship_date.
define variable trans_type as character.
define variable shipto as character.
define variable work_qty as decimal.
define variable undotran as logical no-undo.
define variable msg_ct as integer.
define variable errors as logical.
define variable yn as logical.
define variable from_site as character.
define variable to_site as character.
define variable from_location as character.
define variable to_location as character.
define variable temp_recid as recid.
define variable rejected as logical.
define variable lotserials_req as logical.
define variable qty_bkfl as decimal.
define variable shift as character.
define variable input_que_op_to_ck as integer.
define variable input_que_qty_chg as decimal.
define variable std_run_hrs like op_act_run.
define variable earn_code as character.
define variable result_status     as character no-undo.
define variable msgno             as integer   no-undo.
define variable msgtxt            as character no-undo.
define variable prev_milestone_op as integer   no-undo.

define new shared variable tr_recno as recid.
define new shared variable h_wiplottrace_procs as handle no-undo.
define new shared variable h_wiplottrace_funcs as handle no-undo.
define variable exit like mfc_logical no-undo.
define variable iss_trnbr like tr_trnbr no-undo.
define variable rct_trnbr like tr_trnbr no-undo.

{wlfnc.i} /*FUNCTION FORWARD DECLARATIONS*/
{wlcon.i}
if is_wiplottrace_enabled() then do:
   {gprunmo.i &program=""wlpl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_procs"""}
   {gprunmo.i &program=""wlfl.p"" &module="AWT"
      &persistent="""persistent set h_wiplottrace_funcs"""}
end.
define buffer abs_wiplot for abs_mstr.
define workfile wf_abs_wiplot no-undo
   field id like wr_lot
   field op like wr_op
   field lotserial like tr_serial
   field qty like abs_mstr.abs_qty.

{rcwabsdf.i new}


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 

   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
abs_mstr.abs_shipfrom         colon 28 label {&resubis_p_1}
   si_desc                       at 45 no-label

   abs_mstr.abs_id               colon 28 label {&resubis_p_2}
   skip(1)
   ship_dt                       colon 28
   eff_date                      colon 28
 SKIP(.4)  /*GUI*/
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

abs_mstr.abs_id:label in frame a = getTermLabel("SHIPPER_ID", 25).

for first mfc_ctrl
      fields (mfc_char mfc_field mfc_label mfc_logical
      mfc_module mfc_seq mfc_type)
      where mfc_field = "rpc_using_new" no-lock:
end. /* FOR FIRST MFC_CTRL */

if not available mfc_ctrl or mfc_logical = false then do:
   {pxmsg.i &MSGNUM=5119 &ERRORLEVEL=3}
   message.
   message.
   leave.
end.

for first abs_mstr
      fields (abs_canceled abs_eff_date abs_id abs_inv_mov abs_qty
      abs_shipfrom abs_shipto abs_ship_qty abs_shp_date
      abs_status abs_type abs__qad01)
      where recid(abs_mstr) = global_recid no-lock:
end. /* FOR FIRST ABS_MSTR */

if available abs_mstr and abs_id begins "s" and
   (can-find
   (im_mstr where
   im_inv_mov = abs_inv_mov and
   im_tr_type = "ISS-WO") or
   abs_type = "u") then do:

   for first si_mstr
         fields (si_desc si_entity si_site)
         where si_site = abs_shipfrom no-lock:
   end. /* FOR FIRST SI_MSTR */

   display
      abs_shipfrom
      si_desc
      substring(abs_id,2,50) @ abs_id
   with frame a.
end.
assign
   ship_dt = today
   eff_date = today.
display ship_dt eff_date with frame a.

mainloop:
repeat:
/*GUI*/ if global-beam-me-up then undo, leave.

   assign
      msg_ct = 0
      errors = no.

   do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.

      for each sr_wkfl where sr_userid = mfguser exclusive-lock:
         delete sr_wkfl.
      end.
      {gprun.i ""gplotwdl.p""}
/*GUI*/ if global-beam-me-up then undo, leave.

   end.
/*GUI*/ if global-beam-me-up then undo, leave.


   /* MOVE CODE BELOW TO AN INTERNAL PROCEDURE */

   run prompt_next_previous.
   if exit then leave.

   for first abs_mstr
         fields (abs_canceled abs_eff_date abs_id abs_inv_mov abs_qty
         abs_shipfrom abs_shipto abs_ship_qty abs_shp_date
         abs_status abs_type abs__qad01)
         where abs_shipfrom = input abs_shipfrom
         and   abs_id       = "s" + input abs_id no-lock:
   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* FOR FIRST ABS_MSTR */

   if not available abs_mstr then do:
      {pxmsg.i &MSGNUM=8145 &ERRORLEVEL=3}
      bell.
      undo, retry.
   end.

   {gprun.i ""gpsiver.p"" "(input abs_shipfrom,
                                       input ?,
                                       output return_int)"}
/*GUI*/ if global-beam-me-up then undo, leave.

   if return_int = 0
   then do:
      {pxmsg.i &MSGNUM=725 &ERRORLEVEL=3}
      /* USER DOES NOT HAVE ACCESS TO THIS SITE */
      next-prompt abs_shipfrom.
      undo, retry.
   end.

   if not can-find
      (im_mstr where
      im_inv_mov = abs_inv_mov and
      im_tr_type = "ISS-WO") and
      (abs_type <> "u") then do:

      {pxmsg.i &MSGNUM=5106 &ERRORLEVEL=3}
      undo mainloop, retry mainloop.
   end.

   if abs_canceled then do:
      {pxmsg.i &MSGNUM=5885 &ERRORLEVEL=3}
      /* Shipper canceled */
      undo mainloop, retry mainloop.
   end.

   if substring(abs_status,2,1) = "y" then do:
      {pxmsg.i &MSGNUM=8146 &ERRORLEVEL=2}
   end.

   if substring(abs_status,1,1) <> "y" then do:
      {pxmsg.i &MSGNUM=8147 &ERRORLEVEL=2}
   end.

   assign
      shipto = abs_shipto
      abs_recid = recid(abs_mstr).

   for first si_mstr
         fields (si_desc si_entity si_site)
         where si_site = abs_shipfrom no-lock:
   end. /* FOR FIRST SI_MSTR */

   display si_desc with frame a.

   seta:
   do with frame a on error undo:
/*GUI*/ if global-beam-me-up then undo, leave.

      update ship_dt eff_date with frame a.

      {gpglef1.i &entity = si_entity
         &module = ""IC""
         &date = eff_date
         &prompt = "eff_date"
         &frame = "a"
         &loop = "seta"
         }
   end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* DO WITh FRAME A: SETA: */

   for first ad_mstr
         fields (ad_addr)
         where ad_addr = abs_shipto no-lock:
   end. /* FOR FIRST AD_MSTR */

   assign
      abs_shipvia = substring(abs__qad01,1,20)
      abs_fob = substring(abs__qad01,21,20)
      abs_carr_ref = substring(abs__qad01,41,20)
      abs_trans_mode = substring(abs__qad01,61,20)
      abs_veh_ref = substring(abs__qad01,81,20).

   for each work_abs_mstr exclusive-lock:
      delete work_abs_mstr.
   end.

   /* EXPLODE SHIPPER TO GET ORDER DETAIL */

   {gprun.i ""rcsoisa.p"" "(input recid(abs_mstr))"}
/*GUI*/ if global-beam-me-up then undo, leave.


   /*EDIT CHECK OF WIP MATERIAL*/

   for each work_abs_mstr no-lock

         where work_abs_mstr.abs_id begins "i"
         and   work_abs_mstr.abs_qty <> work_abs_mstr.abs_ship_qty,

         each wo_mstr
         fields (wo_lot wo_part wo_site) no-lock
         where wo_lot = abs_order,

         each wr_route
         fields (wr_auto_lbr wr_lot wr_mch wr_milestone wr_op
         wr_qty_outque wr_run wr_wipmtl_part wr_wkctr) no-lock
         where wr_lot = abs_order
         and   wr_op  = integer(abs_line)
         break by abs_order by abs_line by abs_item:
/*GUI*/ if global-beam-me-up then undo, leave.


      accumulate ((abs_qty - abs_ship_qty) * decimal(abs__qad03))
         (sub-total by abs_item).

      if last-of(abs_item) then do:

         /*DETERMINE IF WIP ITEM OR IF COMPONENT ITEM*/
         assign
            operation_wip_mtl = no.

         if abs_item = "" then
            operation_wip_mtl = yes.

         else

         if abs_item = wr_wipmtl_part then
            operation_wip_mtl = yes.

         if operation_wip_mtl then do for prev_wr_route:
               /*CHECK INPUT QUEUE THIS OP*/

               /* FOURTH INPUT PARAMETER CHANGED FROM (ACCUM sub-total  */
               /* BY abs_item (abs_qty - abs_ship_qty))  TO             */

               {gprun.i ""rechkq.p""
                  "(input wr_route.wr_lot,
                       input wr_route.wr_op,
                       input ""i"",
                       input (accum sub-total
                              by abs_item (abs_qty - abs_ship_qty)
                               * decimal(abs__qad03)),
                       input-output msg_ct)"
                  }
/*GUI*/ if global-beam-me-up then undo, leave.


               find last prev_wr_route
                  where prev_wr_route.wr_lot = wr_route.wr_lot
                  and prev_wr_route.wr_op < wr_route.wr_op
                  no-lock no-error.

               if available prev_wr_route
                  and prev_wr_route.wr_milestone
               then do:
                  /*CHECK OUTPUT QUEUE PREV OP*/

                  /* FOURTH INPUT PARAMETER CHANGED FROM - (ACCUM    */
                  /* SUB-TOTAL BY abs_item (abs_qty - abs_ship_qty)) */
                  /* TO - (ACCUM sub-total BY abs_item (abs_qty -    */

                  {gprun.i ""rechkq.p"" "(input prev_wr_route.wr_lot,
                        input prev_wr_route.wr_op,
                        input ""o"",
                        input - (accum sub-total
                                 by abs_item (abs_qty - abs_ship_qty)
                                              * decimal(abs__qad03)),
                        input-output msg_ct)"}
/*GUI*/ if global-beam-me-up then undo, leave.


               end.

               /*ADDED FOLLOWING SECTION*/
               if available prev_wr_route
                  and not prev_wr_route.wr_milestone
               then do:
                  do transaction:

                     qty_bkfl = (accum sub-total

                        by abs_item (abs_qty - abs_ship_qty)
                        * decimal(abs__qad03))
                        - wr_qty_outque.
                  end.

                  /*DETERMINE INPUT QUEUE OP TO CHECK; */
                  /*COULD BE PRIOR NONMILESTONES       */

                  {gprun.i ""reiqchg.p"" "(input prev_wr_route.wr_lot,
                                                 input prev_wr_route.wr_op,
                                                 input qty_bkfl,
                                                 output input_que_op_to_ck,
                                                 output input_que_qty_chg)"
                     }
/*GUI*/ if global-beam-me-up then undo, leave.


                  {gprun.i ""rechkq.p"" "(input prev_wr_route.wr_lot,
                                                input input_que_op_to_ck,
                                                input ""i"",
                                                input input_que_qty_chg,
                                                input-output msg_ct)"}
/*GUI*/ if global-beam-me-up then undo, leave.

               end.
               /*END SECTION*/

               if is_wiplottrace_enabled()
                  and is_operation_queue_lot_controlled(wr_route.wr_lot,
                           wr_route.wr_op, OUTPUT_QUEUE)
               then do:
                  for each abs_wiplot no-lock
                     where abs_wiplot.abs_shipfrom =
                             work_abs_mstr.abs_shipfrom
                       and abs_wiplot.abs_par_id =
                            work_abs_mstr.abs_id
                       and abs_id begins 'w' + work_abs_mstr.abs_id + '/'
                  :

                     prev_milestone_op = prev_milestone_operation
                        (abs_wiplot.abs_order, integer(abs_wiplot.abs_line)).
                     for first prev_milestone_wr_route
                        where wr_lot = abs_wiplot.abs_order
                          and wr_op  = prev_milestone_op no-lock:
                     end. /* FOR FIRST prev_milestone_wr_route */

                     /* ADDED 12th(msgno) AND 13th(msgtxt) PARAMETER */
                     run check_change_wip_qty_alloc_qoh
                        in h_wiplottrace_procs
                        (input  abs_wiplot.abs_order,
                         input  prev_milestone_op,
                         input  abs_wiplot.abs_lotser,
                         input  abs_wiplot.abs_ref,
                         input  wo_site,
                         input  prev_milestone_wr_route.wr_wkctr,
                         input  prev_milestone_wr_route.wr_mch,
                         input  OUTPUT_QUEUE,
                         input  abs_wiplot.abs_order,
                         input  prev_milestone_operation
                                (abs_wiplot.abs_order,
                                 integer(abs_wiplot.abs_line)),
                         input  - abs_wiplot.abs_qty,
                         output msgno,
                         output msgtxt,
                         output result_status).

                     if result_status = FAILED_EDIT
                     then do:
                        {pxmsg.i &MSGNUM=msgno &ERRORLEVEL=4 &MSGARG1=msgtxt}
                        errors = yes.
                     end.
                     else
                        if result_status = PASSED_EDIT and
                           msgno        <> 0
                        then do:
                           {pxmsg.i &MSGNUM=msgno &ERRORLEVEL=2 &MSGARG1=msgtxt}
                        end.

                     run check_change_wip_qty_alloc_qoh
                        in h_wiplottrace_procs
                        (input  abs_wiplot.abs_order,
                         input  prev_milestone_op,
                         input  abs_wiplot.abs_lotser,
                         input  abs_wiplot.abs_ref,
                         input  wo_site,
                         input  shipto,
                         input  "",
                         input  OUTPUT_QUEUE,
                         input  abs_wiplot.abs_order,
                         input  integer(abs_wiplot.abs_line),
                         input  abs_wiplot.abs_qty,
                         output msgno,
                         output msgtxt,
                         output result_status).

                     if result_status = FAILED_EDIT
                     then do:
                        {pxmsg.i &MSGNUM=msgno &ERRORLEVEL=4 &MSGARG1=msgtxt}
                        errors = yes.
                     end.
                     else
                        if result_status = PASSED_EDIT and
                           msgno        <> 0
                        then do:
                           {pxmsg.i &MSGNUM=msgno &ERRORLEVEL=2 &MSGARG1=msgtxt}
                        end.
                  end. /* FOR EACH abs_wiplot */
               end. /* IF is_wiplottrace_enabled() */

            end.
         end.
/*GUI*/ if global-beam-me-up then undo, leave.

      end.

      /*FORCE A PAUSE IF NECESSARY*/
      {gprun.i ""repause.p"" "(input msg_ct)"}
/*GUI*/ if global-beam-me-up then undo, leave.


      /*EDIT CHECK OF COMPONENT MATERIAL*/

      for each work_abs_mstr no-lock

            where work_abs_mstr.abs_id begins "i"
            and   work_abs_mstr.abs_qty <> work_abs_mstr.abs_ship_qty,

            each wo_mstr
            fields (wo_lot wo_part wo_site) no-lock
            where wo_lot = abs_order,

            each wr_route
            fields (wr_auto_lbr wr_lot wr_mch wr_milestone wr_op
            wr_qty_outque wr_run wr_wipmtl_part wr_wkctr) no-lock
            where wr_lot = abs_order
            and   wr_op  = integer(abs_line)
            break by abs_order by abs_line by abs_item
            by abs_site by abs_loc by abs_lot by abs_ref:
/*GUI*/ if global-beam-me-up then undo, leave.


         accumulate ((abs_qty - abs_ship_qty) * decimal(abs__qad03))
            (sub-total by abs_ref).

         if last-of(abs_ref) then do:
            /*DETERMINE IF WIP ITEM OR IF COMPONENT ITEM*/
            assign
               operation_wip_mtl = no.

            if abs_item = "" then
               operation_wip_mtl = yes.

            else

            if abs_item = wr_wipmtl_part then
               operation_wip_mtl = yes.

            if not operation_wip_mtl then do:
               work_qty =

               - (accum sub-total by abs_ref ((abs_qty - abs_ship_qty)
                  * decimal(abs__qad03))).

               /*ADDED BLANKS FOR TRNBR AND TRLINE*/

               {gprun.i ""icedit.p"" "(input ""ISS-WO"",
                     input abs_site,
                     input abs_loc,
                     input abs_item,
                     input abs_lotser,
                     input abs_ref,
                     input work_qty,
                     input abs__qad02,
                     input """",
                     input """",
                     output undotran)"}
/*GUI*/ if global-beam-me-up then undo, leave.


               if undotran then errors = yes.
            end.
         end.
      end.
/*GUI*/ if global-beam-me-up then undo, leave.


      if errors then do:
         {pxmsg.i &MSGNUM=5113 &ERRORLEVEL=1}
         undo mainloop, retry mainloop.
      end.

      yn = yes.
      {mfmsg01.i 32 1 yn}
      if yn <> yes then undo, retry.

      /*DO PROCESSING*/

      for each work_abs_mstr no-lock
            where work_abs_mstr.abs_qty <> work_abs_mstr.abs_ship_qty:
         if work_abs_mstr.abs_id begins 'w' then next.

         if abs_id begins "c" then do transaction:
            /*UNPLANNED ISSUES FOR CONTAINERS*/

            for first pt_mstr
                  fields (pt_iss_pol pt_loc pt_part pt_prod_line)
                  where pt_part = abs_item no-lock:
            end. /* FOR FIRST PT_MSTR */

            for first in_mstr
                  fields (in_cur_set in_gl_set in_part in_site
                          in_gl_cost_site)
                  where in_part = pt_part
                  and in_site = abs_site no-lock:
            end. /* FOR FIRST IN_MSTR */

            {gpsct03.i &cost=sct_cst_tot}

            assign
               rmks = getTermLabel("CONTAINER_ISSUE",15)
               transtype = "ISS-UNP"
               part = abs_item
               global_part = abs_item
               so_job = ""
               addr = shipto

               unit_cost = glxcst
               cr_acct = ""
               cr_sub = ""
               issrct = "ISS"
               cr_cc = ""
               project = ""
               transtype = "ISS-UNP"
               issrct = "ISS"
               conv = 1.

               if not pt_iss_pol then do:
                  {gprun.i ""glactdft.p"" "(input ""WO_FLR_ACCT"",
                                            input pt_prod_line,
                                            input abs_site,
                                            input """",
                                            input """",
                                            input no,
                                            output dr_acct,
                                            output dr_sub,
                                            output dr_cc)"}
/*GUI*/ if global-beam-me-up then undo, leave.

               end.
               else do:
                  {gprun.i ""glactdft.p"" "(input ""WO_COP_ACCT"",
                                            input pt_prod_line,
                                            input abs_site,
                                            input """",
                                            input """",
                                            input no,
                                            output dr_acct,
                                            output dr_sub,
                                            output dr_cc)"}
/*GUI*/ if global-beam-me-up then undo, leave.

               end.

            create sr_wkfl.

            assign
               sr_userid = mfguser
               sr_lineid = abs_line
               sr_site = abs_site
               sr_loc = abs_loc
               sr_lotser = abs_lotser
               sr_ref = abs_ref
               sr_qty = abs_qty - abs_ship_qty
               .
            temp_recid = recid(sr_wkfl).

            /* Added input parameter "i_addship" to bypass shipper-creation code */

            {gprun.i ""icintra.p""  "('', ?, '', false)" }
/*GUI*/ if global-beam-me-up then undo, leave.


            if available sr_wkfl then delete sr_wkfl.
         end.
         else
            if abs_id begins "i" then do:

            for first wo_mstr
                  fields (wo_lot wo_part wo_site)
                  where wo_lot = abs_order no-lock:
            end. /* FOR FIRST WO_MSTR */

            for first wr_route
                  fields (wr_auto_lbr wr_lot wr_mch wr_milestone wr_op
                  wr_qty_outque wr_run wr_wipmtl_part wr_wkctr)
                  where wr_lot = abs_order
                  and   wr_op  = integer(abs_line) no-lock:
            end. /* FOR FIRST WR_ROUTE */

            /*DETERMINE IF WIP ITEM OR IF COMPONENT ITEM*/
            assign
               operation_wip_mtl = no.

            if abs_item = "" then
               operation_wip_mtl = yes.

            else

            if abs_item = wr_wipmtl_part then
               operation_wip_mtl = yes.

            if operation_wip_mtl then do for prev_wr_route:
                  /*IF WIP ITEM THEN MOVE FROM PREVIOUS OP TO THIS OP*/

                  find last prev_wr_route
                     where prev_wr_route.wr_lot = wr_route.wr_lot
                     and prev_wr_route.wr_op < wr_route.wr_op
                     no-lock no-error.

                  if available prev_wr_route then do:

                     for first wc_mstr
                           fields (wc_dept wc_mch wc_wkctr)
                           where wc_wkctr = wr_wkctr
                           and   wc_mch   = wr_mch no-lock:
                     end. /* FOR FIRST WC_MSTR  */
                     /* TRANSFER BETWEEN OPERATION SHOULD NOT BE BASED  */
                     /* ON WIP LOT SHIPPER DATA WHEN THE ITEM IS        */
                     /* NOT WIP LOT TRACE CONTROLLED                    */
                     if is_wiplottrace_enabled()
                     and is_operation_queue_lot_controlled(wr_lot, wr_op,
                                                               OUTPUT_QUEUE)
                        then do transaction:
/*GUI*/ if global-beam-me-up then undo, leave.

                        for each abs_wiplot no-lock
                              where
                              abs_wiplot.abs_shipfrom =
                              work_abs_mstr.abs_shipfrom
                              and abs_wiplot.abs_par_id =
                              work_abs_mstr.abs_id
                             and abs_id begins 'w' + work_abs_mstr.abs_id + '/':
/*GUI*/ if global-beam-me-up then undo, leave.

                           trans_type = "SUBSHIP".

                           /*CREATE OP_HIST RECORD*/
                           {gprun.i ""reophist.p"" "(input trans_type,
                                                        input wr_lot,
                                                        input wr_op,
                                                        input """",
                                                        input wr_wkctr,
                                                        input wr_mch,
                                                        input wc_dept,
                                                        input """",
                                                        input eff_date,
                                                        output ophist_recid)"
                              }
/*GUI*/ if global-beam-me-up then undo, leave.


                           /*MOVE QTY TO NEXT OP*/

                           /* FIFTH INPUT PARAMETER CHANGED FROM           */
                           /* (abs_wiplot.abs_qty) TO (abs_wiplot.abs_qty) */
                           /* DECIMAL(abs_wiplot.abs__qad03)               */

                           /* THE abs_qty FOR WIP LOT SHIPPER IS IN */
                           /* INVENTORY UM.                         */

                           /* FIFTH INPUT PARAMETER RESTORED TO     */
                           /* (abs_wiplot.abs_qty) FROM             */
                           /* (abs_wiplot.abs_qty)                  */
                           /* * DECIMAL(abs_wiplot.abs__qad03)      */


                           {gprun.i ""removea.p""
                              "(input wr_lot,
                                input wr_op,
                                input eff_date,
                                input ophist_recid,
                                input abs_wiplot.abs_qty)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                           /*ADJUST WIP BALANCES ACCORDINGLY*/

                           run move_wip_lot
                              in h_wiplottrace_procs
                              (
                              input abs_wiplot.abs_order,
                              input prev_milestone_operation
                              (
                              abs_wiplot.abs_order,
                              integer(abs_wiplot.abs_line)
                              ),
                              input abs_wiplot.abs_lotser,
                              input abs_wiplot.abs_ref,
                              input abs_wiplot.abs_qty,
                              input wo_site,
                              input wr_wkctr,
                              input wr_mch,
                              input shipto,
                              input ''
                              ).

                           /*SET WIP LOT AND REF IN OP_HIST*/

                           find op_hist where recid(op_hist) = ophist_recid
                              exclusive-lock.

                           assign
                              op_wip_lotser = abs_wiplot.abs_lotser
                              op_wip_ref = abs_wiplot.abs_ref
                              .
                        end.
/*GUI*/ if global-beam-me-up then undo, leave.

                     end.
                     else do:
                        trans_type = "SUBSHIP".

                        /*CREATE OP_HIST RECORD*/
                        {gprun.i ""reophist.p"" "(input trans_type,
                                                     input wr_lot,
                                                     input wr_op,
                                                     input """",
                                                     input wr_wkctr,
                                                     input wr_mch,
                                                     input wc_dept,
                                                     input """",
                                                     input eff_date,
                                                     output ophist_recid)"
                           }
/*GUI*/ if global-beam-me-up then undo, leave.


                        /*MOVE QTY TO NEXT OP*/

                        /* FIFTH INPUT PARAMETER CHANGED FROM     */

                        {gprun.i ""removea.p""
                           "(input wr_lot,
                                input wr_op,
                                input eff_date,
                                input ophist_recid,
                                input (abs_qty - abs_ship_qty)
                                       * decimal(abs__qad03))"}
/*GUI*/ if global-beam-me-up then undo, leave.

                     end.

                     if not wr_milestone then do:
                        do transaction:

                           if (available mfc_ctrl and mfc_logical = yes)
                              then qty_bkfl = - wr_qty_outque.
                           else
                        if (available mfc_ctrl and mfc_logical = no)
                           then do:
                              if abs_qty < 0 then qty_bkfl = 0.
                              else do:
                                 if wr_qty_outque >= 0 then qty_bkfl = 0.
                                 else qty_bkfl = - wr_qty_outque.
                              end. /* IF abs_qty >= 0 */
                           end. /* IF mfc_logical = no */
                        end.

                        /*BUILD COMPONENT BACKFLUSH LIST*/
                        /* ADDED wr_wkctr TO FOLLOWING CALL */
                        {gprun.i ""recrtcl.p""
                           "(input wr_lot, input wr_op,
                           input yes, input qty_bkfl,
                           input eff_date, input yes,
                           input wr_wkctr,
                           output rejected, output lotserials_req)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                        /*ISSUE COMPONENTS IN BACKFLUSH LIST*/

                        {gprun.i ""rebkflis.p""
                           "(input wr_lot, input eff_date,
                           input ophist_recid)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                        /*BACKFLUSH PRIOR NONMILESTONES*/
                        {gprun.i ""rebkflnm.p"" "(input wr_lot,
                           input wr_op,
                           input eff_date, input shift, input trans_type,
                           input qty_bkfl)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                        /*LABOR AND BURDEN TRANSACTIONS*/
                        assign
                           std_run_hrs = 0
                           earn_code = "".
                        if wr_auto_lbr then std_run_hrs = qty_bkfl * wr_run.

                        for first ea_mstr
                              fields (ea_earn ea_type)
                              where ea_type = "1" no-lock:
                        end. /* FOR FIRST EA_MSTR */

                        if available ea_mstr then earn_code = ea_earn.

                        {gprun.i ""relbra.p"" "(input wr_lot,
                                                   input wr_op,
                                                   input wr_wkctr,
                                                   input wr_mch,
                                                   input wc_dept,
                                                   input std_run_hrs,
                                                   input eff_date,
                                                   input earn_code,
                                                   input """",
                                                   input true,
                                                   input ophist_recid)"
                           }
/*GUI*/ if global-beam-me-up then undo, leave.


                        /*REGISTER QTY PROCESSED         */
                        /*(REDUCE INQUE, INCREASE OUTQUE)*/
                        {gprun.i ""rebkfla.p""
                           "(input wr_lot, input wr_op,
                           input ophist_recid, input qty_bkfl)"}
/*GUI*/ if global-beam-me-up then undo, leave.


                     end.

                     /* IF SUPPLIER PERFORMANCE IS ENABLED THEN INVOKE THE PROGRAM
                     THAT UPDATES THE SUPPLIER SCHEDULE IF IT'S A SUBCONTRACT
                     OPERATION */

                     /* MOVED TO AN INTERNAL PROCEDURE TO REDUCE ACTION SEGMENT ERROR */
                     run p-poscsup.

                  end.
               end.
               else do:
                  /*IF COMPONENT ITEM THEN*/
                  /*TRANSFER TO WORKCENTER LOCATION IF NECESSARY*/

                  for first pt_mstr
                        fields (pt_iss_pol pt_loc pt_part pt_prod_line)
                        where pt_part = abs_item no-lock:
                  end. /* FOR FIRST PT_MSTR */

                  assign
                     from_site = abs_site
                     from_location = abs_loc
                     to_site = wo_site
                     to_location = pt_loc.

                  for first loc_mstr
                        fields (loc_loc loc_site)
                        where loc_site = wo_site
                        and   loc_loc  = wr_wkctr no-lock:
                  end. /* FOR FIRST LOC_MSTR */

                  if available loc_mstr then to_location = wr_wkctr.

                  if from_site <> to_site or from_location <> to_location
                  then do:
                     assign
                        expire = ?
                        assay = 0
                        grade = "".

                     for first ld_det
                           fields (ld_assay ld_expire ld_grade ld_loc
                           ld_lot ld_part ld_ref ld_site)
                           where ld_part = abs_item
                           and ld_site = abs_site
                           and ld_loc = abs_loc
                           and ld_lot = abs_lotser
                           and ld_ref = abs_ref

                           no-lock:
                     end. /* FOR FIRST LD_DET */

                     if available ld_det then
                     assign
                        expire = ld_expire
                        assay  = ld_assay
                        grade  = ld_grade.

                     assign
                        global_part = abs_item
                        transtype = "ISS-TR".

                     {gprun.i ""icxfer.p"" "(input """",
                                                input abs_lotser,
                                                input abs_ref,
                                                input abs_ref,
                                                input ((abs_qty - abs_ship_qty)
                                                        * decimal(abs__qad03)),
                                                input wo_part,
                                                input """",
                                                input """",
                                                input """",
                                                input eff_date,
                                                input from_site,
                                                input from_location,
                                                input to_site,
                                                input to_location,
                                                input no,
                                                input """",
                                                input ?,
                                                input """",
                                                input 0,
                                                output glcost,
                                                output iss_trnbr,
                                                output rct_trnbr,
                                                input-output assay,
                                                input-output grade,
                                                input-output expire)"
                        }
/*GUI*/ if global-beam-me-up then undo, leave.

                  end.
               end.
            end.

            do transaction:
               find abs_mstr
                  where abs_mstr.abs_shipfrom = work_abs_mstr.abs_shipfrom
                  and abs_mstr.abs_id = work_abs_mstr.abs_id
                  exclusive-lock.

               abs_mstr.abs_ship_qty = abs_mstr.abs_qty.
            end.
         end.

         do transaction:
            /* MARK SHIPPER CONFIRMED */
            find abs_mstr where recid(abs_mstr) = abs_recid exclusive-lock.
            assign
               substring(abs_status,2,1) = "y"
               abs_eff_date = eff_date.
            abs_shp_date = ship_dt.
         end.

         release abs_mstr.
         global_recid = abs_recid.
      end.

      if is_wiplottrace_enabled() then
         delete PROCEDURE h_wiplottrace_procs no-error.
      if is_wiplottrace_enabled() then
         delete PROCEDURE h_wiplottrace_funcs no-error.

      PROCEDURE p-poscsup:
         if can-find (mfc_ctrl
            where mfc_field = "enable_supplier_perf"
            and   mfc_logical)
            and
            can-find (_File where _File-name = "vef_ctrl") then
      do:

            /* FOURTH INPUT PARAMETER CHANGED FROM (abs_mstr.abs_qty - */

            /* USING THE REFERENCE work_abs_mstr IN PLACE OF abs_mstr  */

            {gprunmo.i
               &program=""poscsup.p""
               &module="ASP"
               &param="""(input wr_route.wr_lot,
                           input wr_route.wr_op,
                           input ship_dt,
                           input (work_abs_mstr.abs_qty -
                                  work_abs_mstr.abs_ship_qty)
                                  * decimal(work_abs_mstr.abs__qad03))"""}
         end. /* IF CAN_FIND ... */
      end. /* PROCEDURE P_POSCSUP */

      PROCEDURE prompt_next_previous:
         if no then find first abs_mstr.
         exit = yes.
         do with frame a:
            prompt-for abs_shipfrom abs_id
            editing:
               if frame-field = "abs_shipfrom" then do:
                  {mfnp05.i abs_mstr abs_id
                     "(abs_id begins ""s"" ) and
                         (can-find
                             (im_mstr where
                                im_inv_mov = abs_inv_mov and
                                im_tr_type = ""ISS-WO"") or
                          abs_type = ""u"")"
                     abs_shipfrom
                     "input abs_shipfrom" }

                  if recno <> ? then do:
                     for first si_mstr
                           fields (si_desc si_entity si_site)
                           where si_site = abs_shipfrom no-lock:
                     end. /* FOR FIRST SI_MSTR */

                     assign
                        global_site = abs_shipfrom
                        global_lot = abs_id
                        disp_abs_id = substring(abs_id,2,50).

                     display
                        abs_shipfrom
                        si_desc  when (available si_mstr)
                        ""       when (not available si_mstr) @ si_desc
                        disp_abs_id @ abs_id.
                  end.
               end.
               else
                  if frame-field = "abs_id" then do:
                  {mfnp05.i abs_mstr abs_id
                     "(abs_shipfrom = input abs_shipfrom) and
                         (abs_id begins ""s"" ) and
                         (can-find
                             (im_mstr where
                                im_inv_mov = abs_inv_mov and
                                im_tr_type = ""ISS-WO"") or
                          abs_type = ""u"")"
                     abs_id
                     " ""s"" + input abs_id"}

                  if recno <> ? then do:
                     for first si_mstr
                           fields (si_desc si_entity si_site)
                           where si_site = abs_shipfrom no-lock:
                     end. /* FOR FIRST SI_MSTR */

                     assign
                        global_site = abs_shipfrom
                        global_lot = abs_id
                        disp_abs_id = substring(abs_id,2,50).

                     display
                        abs_shipfrom
                        si_desc  when (available si_mstr)
                        ""       when (not available si_mstr) @ si_desc
                        disp_abs_id @ abs_id.
                  end.
               end.
               else do:
                  status input.
                  readkey.
                  apply lastkey.
               end.
            end.
         end.
         exit = no.
      END PROCEDURE.
